package org.ddl.core.strategy.mod;

import org.ddl.core.entity.DataSourceTable;
import org.ddl.core.strategy.DataSourceShardStrategy;

/**
 * 分库取模算法
 * 
 * @author yinjianwei
 * @date Oct 8, 2017 9:31:29 PM
 *
 */
public class ModDataSourceShardStrategy implements DataSourceShardStrategy {

	@Override
	public String getShardType() {
		return "mod";
	}

	@Override
	public DataSourceTable handle(String logicDataSource, int dataSourceShardNum, Long shardValue) {
		long dbPosition = shardValue % dataSourceShardNum;
		String finalDataSourceKey = new StringBuilder().append(logicDataSource).append(dbPosition).toString();
		return new DataSourceTable(finalDataSourceKey, "");
	}

}
